防止matplotlib.pyplot中的科学记数法

您所在的位置:网站首页 matplotlib 关闭绘图 防止matplotlib.pyplot中的科学记数法

防止matplotlib.pyplot中的科学记数法

2024-07-04 14:59| 来源: 网络整理| 查看: 265

防止matplotlib.pyplot中的科学记数法

我们在使用matplotlib.pyplot绘制图像时,如果统计的数据过大图标上就会出现用科学计数法的方式显示,例如

import matplotlib.pyplot as plt import numpy as py # 求平方数 x_values = py.linspace(0, 100000000) y_value = [x**2 for x in x_values] plt.style.use('seaborn') fig, ax = plt.subplots() ax.scatter(x_values, y_value, c=y_value, cmap=plt.cm.Reds, s=20) plt.show()

在这里插入图片描述 可见x轴与y轴上的数据并没有显示原本的格式

解决方法如下

输入以下这行代码

ax.ticklabel_format(style='plain')

import matplotlib.pyplot as plt import numpy as py # 求平方数 x_values = py.linspace(0, 100000000) y_value = [x**2 for x in x_values] plt.style.use('seaborn') fig, ax = plt.subplots() ax.scatter(x_values, y_value, c=y_value, cmap=plt.cm.Reds, s=20) ax.ticklabel_format(style='plain') plt.show()

可得 在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3